package stu.sup.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import stu.sup.dto.ClasstableDTO;
import stu.sup.entity.ClassTable;
import stu.sup.entity.Product;
import stu.sup.entity.ProductTpicInfo;
import stu.sup.mapper.ProductTpicInfoMapper;
import stu.sup.service.IClassTableService;
import stu.sup.service.IPicInfoService;
import stu.sup.service.IProductService;
import stu.sup.service.IproductClassDTOService;

import java.util.ArrayList;
import java.util.List;

@Service
public class productClassDTOServiceImpl implements IproductClassDTOService {
    @Autowired
    private IProductService productService;
    @Autowired
    private IClassTableService classTableService;
    @Autowired
    private IPicInfoService picInfoService;
    @Override
    public List<ClasstableDTO> showAll(String name) {
        List<ClasstableDTO> classtableDTOS=new ArrayList<>();
        Product product=new Product();
        product.setProductName(name);
        List<Product> products =productService.selectByConditional(product);
        System.out.println(products);
        for (Product p:products){
           ClassTable classTable=classTableService.selectbyid(p.getId());
            System.out.println(classTable);
            ProductTpicInfo productTpicInfo=picInfoService.selectById(p.getProductImgId());
           ClasstableDTO classtableDTO=new ClasstableDTO();
           classtableDTO.setProductName(p.getProductName());
           classtableDTO.setProductDesc(p.getProductDesc());
           classtableDTO.setClassName(classTable.getClassName());
           classtableDTO.setProductBrand(classTable.getProductBrand());
           classtableDTO.setProductSaleway(classTable.getProductSaleway());
           classtableDTO.setProductTime(classTable.getProductTime());
           classtableDTO.setProductWeight(classTable.getProductWeight());
           classtableDTO.setProductPlace(classTable.getProductPlace());
          classtableDTO.setUrl(productTpicInfo.getPicUrl());
          classtableDTO.setProductPrice(p.getProductPrice());
          classtableDTOS.add(classtableDTO);
        }
        System.out.println(classtableDTOS);
        return classtableDTOS;
    }
}
